define(function(require, exports, module) {
    var ALL = require("../../common/all"),
        CONFIG = ALL.CONFIG,
        METHOD = ALL.METHOD,
        Dialog = ALL.Dialog,
        Init = ALL.Init;


    var _Dialog = new Dialog({
        title : "提示",
        content : "<p>提交后将进入审核流程，确定是否提交？</p>",
        text4Btn: ["确定", "取消"],
        class4Btn: ["", "line"]
    });


    var _vm = Init.initVue({
        data : {
            id : null,
            check : {},
            disabled : false,
            business : '',                       // 上票方名称
            buslist : [],                        // 上票方搜索列表
            res: {
                code : '',                       // 藏品id
                name : '',
                type : null,                     // 藏品大类
                sub_type : null,                 // 藏品类型
                business : '',                   // 上票方
                price : '',
                count : '',
                max_entrust_buy : '',
                max_entrust_sell : '',
                min_take : '',                   // 最小提货量
                article_id : '',                 // 图文id
                sell_time : ''
            },
            typeList : [],
            artlist : []
        },
        methods: {
            submit : function() {
                var url,flag;

                this.check.$valid();
                flag = this.check.flag;

                if (!flag) { return; }

                if (_vm.id) {
                    url = "collection/update";
                } else {
                    url = "collection/create";
                }

                _Dialog.showUI(function(i) {
                    if (i == 0) {
                        METHOD.loading.show();
                        METHOD.ajax(url,{ data: JSON.stringify(_vm.res)},{type : 'post'}).done(function(){
                            METHOD.loading.hide();
                            METHOD.alert("操作成功").done(function(){
                                if (_vm.disabled) {
                                    window.location.href = "../collection/index.html";
                                } else {
                                    window.location.href = "../collection/notissued.html";
                                }
                            });
                        }).fail(function(){
                            METHOD.loading.hide();
                        });
                    }
                    this.hideUI();
                });
            },
            getType : function() {
                METHOD.loading.show();
                METHOD.ajax("coltype/all_list").done(function(json){
                    METHOD.loading.hide();
                    _vm.typeList = json.data;
                });
                METHOD.ajax("business/simple_list").done(function(json){
                    METHOD.loading.hide();
                    _vm.buslist = json.data;
                });
                METHOD.ajax("collection/article/all_list").done(function(json){
                    METHOD.loading.hide();
                    _vm.artlist = json.data;
                });
                METHOD.loading.hide();
            },
            changeType : function(){
                this.res.sub_type = "";
            }
        },
        computed : {
            changList : function(){
                var arr = [],
                    id = this.res.type;

                this.typeList.forEach(function(v){
                    if (v.id == id) { arr = v.sub_type; }
                });

                return arr;
            }
        }
    });

    _vm.id = METHOD.getQueryParms("id") || null;

    if (_vm.id) {
        METHOD.loading.show();
        METHOD.ajax("collection/detail",{col_id: _vm.id}).done(function(json){
            METHOD.loading.hide();
            _vm.res = json.data.detail;
            if (json.data.detail.status == 3) {
                _vm.disabled = true;
                _Dialog.changeCfg({content : "<p>是否确认修改上市时间？</p>"});
            }
        }).fail(function(){
            METHOD.loading.hide();
        })
    } else {
        _Dialog.changeCfg({content : "<p>提交后将进入审核流程，确定是否提交？</p>"});
    }

    _vm.getType();

});

